package com.sz.stock.bankCardUtils;


import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class CardApiServiceImpl implements ICardApiService {


    @Override
    //身份证实名绑定认证；
    public String checkCard(String name, String cardNum, String id) {       //, String phone
        String host = "https://lundroid.market.alicloudapi.com";
        String path = "/lianzhuo/verifi";
        String method = "GET";
//        String appcode = "97edf69b93d3405ea9ceb07964070cb8";  //不要测试啊，次数有限，下面有成功和失败的例子！！！
        String appcode = "97edf69b93d370cb8";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("acct_name", name);
        querys.put("acct_pan", cardNum);    //银行卡号
        querys.put("cert_id", id);          //身份证
//        querys.put("phone_num", phone);     //手机号码

        /**
         * result用来接收结果查询；
         */
        String result ="";
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //获取response的body
            result=EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
